// import axios from 'axios';
// import env from '../config/env';

// let util = {

// };
// util.title = function(title) {
//     title = title ? title + ' - Home' : 'iView project';
//     window.document.title = title;
// };

// const ajaxUrl = env === 'development' ?
//     'http://127.0.0.1:8888' :
//     env === 'production' ?
//     'https://www.url.com' :
//     'https://debug.url.com';

// util.ajax = axios.create({
//     baseURL: ajaxUrl,
//     timeout: 30000
// });

// export default util;
import _ from 'lodash';

let util = {};
util.title = function (title) {
    title = title ? title + ' - Home' : 'Demo project';
    window.document.title = title;
};
/**
 * 合并对象
 * @returns {*}
 */
util.merge=function () {
    let ore;
    for (let li in arguments){

        if(!util.empty(arguments[li+1])){
            ore=merge(arguments[li],arguments[li+1])
        }else{
            ore=merge(ore,arguments[li])
        }
    }
    return ore;
    function merge(obj1,obj2){

        let obj3={};
        for (let li15 in obj1){
            obj3[li15]=obj1[li15];
        }
        for (let li16 in obj2){
            obj3[li16]=obj2[li16];
        }

        return obj3;
    }
}
/**
 * 判断是否为空
 * @param valuee
 * @returns {boolean}
 */
util.empty = function ($value) {
    if (typeof $value == 'undefined') {
        return true;
    }
    if ($value === '0') {
        return true;
    }

    if ($value === null || $value === 0 || $value === '') {
        return true;
    }

    if (typeof $value == 'string' && $value.length > 0) {
        return false;
    }


    if (typeof $value === 'object') {
        for (var li in $value) {
            return false;
        }
        return true;
    }
    if (isNaN($value) && typeof $value == 'number') {
        return true;
    }
    if ($value === false) {
        return true;
    }

    return false;
}
/**
 * 连续数组转递归数组
 * @param $array
 * @param $p
 * @param $ai
 * @param $start
 * @param $lv
 * @param $type
 * @returns {{}}
 */
util.recursion = function ($array, $p = 'pid', $ai = 'id', $start = 0, $lv = 0, $type = 1) {

    let $re = {};
    let $lv1 = $lv++;
    for (let $k in $array) {
        let $v =$array[$k];
        if ($v[$p] == $start) {
            $re[$v[$ai]] = $v;
            $re[$v[$ai]]['lv'] = $lv;
            _.unset($array[$k]);
            if ($type != 1) {
                $re = $re + util.recursion($array, $p, $ai, $v[$ai], $lv1, $type);
            } else {
                $re[$v[$ai]]['sub'] = util.recursion($array, $p, $ai, $v[$ai], $lv, $type);
            }
        }
    }
    return $re;
}
/**
 * 数组转对象
 * @param $array
 * @returns {{}}
 * @constructor
 */
util.AtoO=function($array){
    let re ={};
    for(let li in $array){
        if(typeof $array[li] == 'Array'){

        }
        re[li]=$array[li];
    }
    return re;
}

export default util;